<template>
	<view class="receive-box">
		<u--input placeholder="请输入优惠券卡号/code" v-model="keyword" border="bottom" clearable></u--input>
		<view class="copy-btn"><u-button @click="clipboard" type="success" text="从剪贴板获取优惠券卡号"></u-button></view>
		<BottomBtn title="领取" @change="receiveCoupon"></BottomBtn>
	</view>
</template>

<script>

import BottomBtn from '@/components/bottomBtn.vue';
export default {
	components: { BottomBtn },
	data() {
		return {
			keyword: ''
		};
	},
	methods: {
		// 从剪贴板获取数据赋值到输入框
		clipboard() {
			uni.getClipboardData({
				success: res => {
					this.keyword = res.data;
				}
			});
		},
		// 领取优惠券
		async receiveCoupon() {
			const res = await this.$api.coupon.receiveCoupon({ couponCode: this.keyword });
			if (res.code == 200) {
				uni.showToast({
					icon: 'none',
					title: '领取成功'
				});
				this.keyword = ""
			}
		}
	}
};
</script>

<style lang="scss">
.receive-box {
	background: #fff;
	padding: 120rpx 80rpx 150rpx;
	.copy-btn {
		padding-top: 130rpx;
	}
}
</style>
